package robot.airplane.ticket.unittest;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.URL;

import java.net.HttpURLConnection;

public class main {
		
	public static void main(String[] args) throws Exception {
		String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0";
		String url = "http://booknow.jetstar.com/Search.aspx?culture=vi-VN";
		URL obj = new URL(url);
		HttpURLConnection con = (HttpURLConnection) obj.openConnection();
 
		//add reuqest header
		con.setRequestMethod("POST");
		con.setRequestProperty("User-Agent", USER_AGENT);
		con.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
		con.setRequestProperty("Accept-Encoding", "gzip, deflate");
		con.setRequestProperty("Accept-Language", "en-US,en;q=0.8,fil;q=0.6,vi;q=0.4");
		con.setRequestProperty("Referer", "http://booknow.jetstar.com/Search.aspx?culture=vi-VN");
		con.setRequestProperty("Connection", "keep-alive");
		con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
		con.setRequestProperty("Cookie", "__utma=20450727.751628608.1388797127.1397224720.1397229113.6; 34092332-VID=111630202902243; superT_v1=1396105512994.804172%3A5%3A3%3A17; s_fid=413F550C8B259E9A-309EE9464F5AD34D; s_nr=1396105706461; superT_v1=1396105512994.804172%3A5%3A3%3A17; k_visit=2; __iid=; __RC=5; __R=3; __utmz=20450727.1397055342.4.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); txtOrigin#01=Tp.H%u1ED3%20Ch%ED%20Minh%20%28SGN%29; txtOriginCityCode#01=SGN; txtDestination#01=%u0110%E0%20N%u1EB5ng%20%28DAD%29; txtDestinationCityCode#01=DAD; txtDepart#01=30/04/2014; txtReturn#01=; ddlCurrency#01=VND; ddlAdults#01=1; ddlKids#01=0; rdoFlightTypeReturn#01=undefined; rdoFlightTypeOneWay#01=checked; rdoTravelPrefFixed#01=checked; rdoTravelPrefCheap#01=undefined; compactSearchSubmit#01=1397232890003; sessionculture=vi-VN; __utmc=20450727; s_cc=true; s_sq=jetstarprd%3D%2526pid%253D%25252Fhome%2526pidt%253D1%2526oid%253DT%2525C3%2525ACm%252520chuy%2525E1%2525BA%2525BFn%252520bay%2526oidt%253D3%2526ot%253DSUBMIT; __utmb=20450727.24.9.1397232557591; gpv_pn=%2Fhome; gpv_v1=%2Fhome; ASP.NET_SessionId=se5nkaq41eh3ae55rshfhu45; skysales=420733450.20480.0000; multitabtimestamp=1397232564544.94; __uif=__uid%3A13879894020270268%7C__ui%3A5%7C__create%3A1387989403; multitabcounttimestamp=3; 34092332-SKEY=7648035263933871237; HumanClickSiteContainerID_34092332=STANDALONE; skySearchSubmit=1397230492325; RadioButtonMarketStructure@vi-vn=OneWay; TextBoxMarketOrigin1@vi-vn=Th%E0nh%20ph%u1ED1%20H%u1ED3%20Ch%ED%20Minh%20%28SGN%29; TextBoxMarketDestination1@vi-vn=%u0110%E0%20N%u1EB5ng%20%28DAD%29; TextboxDepartureDate1@vi-vn=22/04/2014; TextboxDestinationDate1@vi-vn=; DropDownListCurrency@vi-vn=VND; ADT@vi-vn=1; CHD@vi-vn=0; INFANT@vi-vn=0; RadioButtonSearchBy@vi-vn=SearchStandard; AKSB=s=1397232879275&r=http%3A//booknow.jetstar.com/Search.aspx%3Fculture%3Dvi-VN; session_start_time=1397232503752; superT_s1=1397232513927.156290; gig3pc=1; superT_s1=1397232513927.156290; SiteCore_POS=Vietnam; Country_POS=vn-vi");
		con.setRequestProperty("Content-Length", "1929");
 
		String urlParameters = "ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListCurrency=VND&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListFareTypes=I&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDay1=30&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDay2=1&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketDay3=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketMonth1=2014-4&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketMonth2=1968-1&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListMarketMonth3=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_ADT=1&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_CHD=0&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24DropDownListPassengerType_INFANT=0&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24RadioButtonMarketStructure=OneWay&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketDestination1=DAD&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketDestination2=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketDestination3=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketOrigin1=SGN&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketOrigin2=&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24TextBoxMarketOrigin3=&ControlGroupSearchView%24ButtonSubmit=&__VIEWSTATE=%2FwEPDwUBMGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFJ01lbWJlckxvZ2luU2VhcmNoVmlldyRtZW1iZXJfUmVtZW1iZXJtZSDCMtVG%2F1lYc7dy4fVekQjBMvD5&culture=vi-VN&date_picker=&go-booking=&pageToken=sLkmnwXwAsY%3D&ControlGroupSearchView%24AvailabilitySearchInputSearchView%24fromCS=yes";
 
		// Send post request
		con.setDoOutput(true);
		DataOutputStream wr = new DataOutputStream(con.getOutputStream());
		wr.writeBytes(urlParameters);
		wr.flush();
		wr.close();
 
		int responseCode = con.getResponseCode();
		System.out.println("\nSending 'POST' request to URL : " + url);
//		System.out.println("Post parameters : " + urlParameters);
		System.out.println("Response Code : " + responseCode);
 
		BufferedReader in = new BufferedReader(
		        new InputStreamReader(con.getInputStream()));
		String inputLine;
		StringBuffer response = new StringBuffer();
 
		while ((inputLine = in.readLine()) != null) {
			response.append(inputLine);
		}
		in.close();
 
		//print result
		System.out.println(response.toString());
	}

}
